<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
session_set_cookie_params(0);
session_start();
$config = parse_ini_file(dirname(__FILE__) . '/config.ini', true);
require_once('/libraries/PHPMailer/class.phpmailer.php');
//var_dump($config);
require('libraries/Smarty/Smarty.class.php');

$smarty = new Smarty();

//$smarty->force_compile = true;
//$smarty->debugging = true;
//$smarty->caching = true;
//$smarty->cache_lifetime = 120;
$smarty->template_dir = "templates/";
$image_dir = $_SERVER['SERVER_NAME'] . '/templates/images/';
$temp_dir = $_SERVER['DOCUMENT_ROOT'] . '/templates/';

//var_dump($template_dir);
//die();
//$smarty->assign($image_dir,"image_dir");
//$smarty->assgin($temp_dir,"temp_dir");
$connect = mysql_connect($config['config']['hostname'], $config['config']['username'], $config['config']['password'], true)
		or die("Connection error!");
mysql_select_db($config['config']['database'])
		or die("Database not found!");
mysql_set_charset('utf8', $connect);

if (isset($_SESSION['email']))
	$smarty->assign("session", $_SESSION['email']);
else
	$smarty->assign("session", '');

// Có khuyến mãi hay không?
$promotionbytime = mysql_fetch_array(mysql_query("select * from promotion_time"));
$currenttime = gmdate('Y-m-d H:i:s', time() + 7 * 3600);

if ($promotionbytime['enable'] == 1 &&
		$promotionbytime["datebegin"] <= $currenttime &&
		$promotionbytime["dateend"] > $currenttime) {
	$promotion_start = 1;
} else {
	$promotion_start = 0;
}
$smarty->assign("promotion_start", $promotion_start);
$smarty->assign("promotionbytime", $promotionbytime);
// End - khuyến mãi
// ai đang loginned
if (isset($_SESSION['email']))
	$session_email = $_SESSION['email'];
else
	$session_email = null;
$user_loginned1 = mysql_fetch_array(mysql_query("select * from user where email ='{$session_email}'"));
if ($user_loginned1["idpermission"] == 1)
	$user_loginned = "admin";
elseif ($user_loginned1["idpermission"] == 4)
	$user_loginned = "user";
else if ($session_email == '' || !isset($session_email))
	$user_loginned = "none";
else
	$user_loginned = "staff";

if ($user_loginned1["idpermission"] == 2)
	$user_loginned_staff = "banhang";
else
if ($user_loginned1["idpermission"] == 3)
	$user_loginned_staff = "ketoan";
else
	$user_loginned_staff = "";
// end

$smarty->assign("user_loginned_staff", $user_loginned_staff);
$smarty->assign("user_loginned", $user_loginned);
$smarty->assign("session_email", $session_email);
include("logic/layouts.php");